<?php

namespace App\Enums;

/**
 * 生产工单订单状态枚举
 */
enum ProductionOrderStatus: int
{
    case PLAN = 1; //计划
    case PLAN_CONFIRM = 2; // 计划确认
    case ORDER_DOWN = 3; // 下达
    case PLAN_START = 4; // 开工
    case PLAN_CLOSE = 5; // 完工
    case CLOSE_CASE = 6; // 结案
    case SETTLEMENT = 7; // 结算

    /**
     * name
     *
     * @return string
     */
    public function label(): string
    {
        return match ($this) {
            self::PLAN => "计划",
            self::PLAN_CONFIRM => "计划确认",
            self::ORDER_DOWN => "下达",
            self::PLAN_START => "开工",
            self::PLAN_CLOSE => "完工",
            self::CLOSE_CASE => "结案",
            self::SETTLEMENT => "结算",
        };
    }

    /**
     * 根据值获取名称
     * @param $val
     * @return string
     */
    static function labelBy($val){
        $obj = self::tryFrom((int)$val);
        return $obj ? $obj->label() : '';
    }
}
